package cn.itsource.system.service.impl;

import cn.itsource.system.domain.Role;
import cn.itsource.system.domain.Role;
import cn.itsource.system.mapper.RoleMapper;
import cn.itsource.system.service.IRoleService;
import cn.itsource.basic.service.Impl.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author mochen
 * @since 2023-04-01
 */
@Service
public class RoleServiceImpl extends BaseServiceImpl<Role> implements IRoleService {
    
    @Autowired
    private RoleMapper roleMapper;

    @Override
    @Transactional
    public void add(Role role) {
        //保存role
        super.add(role);
        roleMapper.removeRolePermission(role.getId());
        roleMapper.removeRoleMenu(role.getId());
        //保存role_permission
        roleMapper.saveRolePermission(role.getId(),role.getPermissions());
        //保存role_menu
        roleMapper.saveRoleMenu(role.getId(),role.getMenus());

    }
}
